import java.io.IOException;
import org.smartboot.http.server.HttpBootstrap;
import org.smartboot.http.server.HttpRequest;
import org.smartboot.http.server.HttpResponse;
import org.smartboot.http.server.HttpServerHandler;
import org.smartboot.http.server.handler.HttpRouteHandler;
import org.smartboot.socket.enhance.EnhanceAsynchronousChannelProvider;

public class BenchSmart {
	public static void main(String[] args) {
		System.setProperty("java.nio.channels.spi.AsynchronousChannelProvider", EnhanceAsynchronousChannelProvider.class.getName());
		int threadNum = Integer.getInteger("thread", 2);
		byte[] body = "Hello, World!".getBytes();

		HttpBootstrap bootstrap = new HttpBootstrap();
		bootstrap.configuration()
				.serverName("smart")
				.threadNum(threadNum)
				.readBufferSize(Integer.getInteger("readBufSize", 1024 * 4))
				.writeBufferSize(Integer.getInteger("writeBufSize", 1024 * 4))
				.readMemoryPool(Integer.getInteger("readMemPool", 16384 * 1024 * 4))
				.writeMemoryPool(Integer.getInteger("writeMemPool", 10 * 1024 * 1024) * threadNum, threadNum);
		bootstrap.httpHandler(new HttpRouteHandler().route("/plaintext", new HttpServerHandler() {
			@Override
			public void handle(HttpRequest request, HttpResponse response) throws IOException {
				response.setContentLength(body.length);
				response.setContentType("text/plain; charset=UTF-8");
				response.write(body);
			}
		})).setPort(Integer.getInteger("port", 10000)).start();
	}
}
